// pages/cate/cate.js
import ajax from '../../utils/ajax.js'
var sliderWidth = 96;
const app = getApp()

Page({
  goBuy(e){
    app.addToCart(e.currentTarget.dataset)
  },
  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["跑步鞋", "情侣装", "板鞋", "帆布鞋", "运动短T"],
    activeIndex:1,
    sliderOffset: 0,
    sliderLeft: 0,
   cate:[],
   love:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
onLoad: function (options) {
 
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });
     // const aa = resp.data.data.items.list.map(item=>{
      //  item =  item.title.slice(6, 11)
      //   return item
      // })

  ajax.get('http://www.xiongmaoyouxuan.com/api/tab/2?start=0')
    .then(resp => {
      this.setData({
        cate: resp.data.data.items.list
      })
    })
  ajax.get('http://www.xiongmaoyouxuan.com/api/category/1875/items?start=0')
    .then(resp => {
      this.setData({
        love: resp.data.data.items.list
      })
    })
  },
tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})